<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>弓友之家</title>
    <link rel="stylesheet" href="css/mui.css" />
    <link rel="stylesheet" href="fonts/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">商品详情</h1>
		<a class="mui-icon mui-icon-more-filled mui-pull-right shareBtn"></a>
	</header>
	<div class="mui-content">
		<div class="goods-page">
			<!--轮播图-->
			<div id="slider" class="mui-slider" >
				<div class="mui-slider-group mui-slider-loop">
					
				</div>
				<div class="mui-slider-indicator">
					
				</div>
			</div>
			<div class="img"><img src=""/></div>
			<h4 class="name"></h4>
			<div class="mui-clearfix price">
				￥<big></big>
				<small class="integral"></small>
				<div class="mui-pull-right goods_left">
					剩余数量：<span>0</span>
				</div>
			</div>
			<div class="goods-desc">
				<header><span>商品详情</span></header>
				<article class="goods_detail">
					
				</article>
			</div>
			<br />
			<div class="mui-row mui-text-center btnf">
				
			</div>
		</div>
	</div>
	<br /><br />
	<!--分享-->
	<div class="shareWx mui-hidden"> 
		<ul class="mui-list-unstyled">
			<li class="tel"><a href="javascript:void(0)" onclick="shareWeixinMessage(1)">微信好友</a></li>
			<li class="qq"><a href="javascript:void(0)" onclick="shareWeixinMessage(2)">朋友圈</a></li>
		</ul>
		<button type="button" class="cancleShare">取消</button>
	</div>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" charset="utf-8">
	var gid="";
	var goodimg="";
	var goodname="";
	var gooddesc="";
	mui.plusReady(function(){
		var _self=plus.webview.currentWebview();
		gid=_self.gid;
		mui.ajax(H_SRC+'/amier/index/goods_detail',{
			data:{
				token:token,
				gid:gid
			},
			dataType:'json',
			type:'post',
			timeout:10000,             
			success:function(data){ 
				var dataurl=data.data;
				if(data.code == 1){
					//轮播图
					var lb="",dot="";
					if(dataurl.banner==null){
						
					}else{
						var imgs=dataurl.banner.split(",");
						goodimg=H_SRC+''+imgs[0];
						lb+='<div class="mui-slider-item mui-slider-item-duplicate"><a><img src="'+H_SRC+''+imgs[imgs.length-1]+'"></a></div>';
						for(var j=0;j<imgs.length;j++){
							lb+='<div class="mui-slider-item"><a><img src="'+H_SRC+''+imgs[j]+'" /></a></div>';
							dot+='<div class="mui-indicator"></div>';
						}
						lb+='<div class="mui-slider-item mui-slider-item-duplicate"><a><img src="'+H_SRC+''+imgs[0]+'"></a></div>';
					}
					$(".mui-slider-group").html(lb);
					$(".mui-slider .mui-slider-indicator").html(dot);
					var slider = mui("#slider");
	  				slider.slider({interval: 4000});  
					
//					$(".img img").attr("src",H_SRC+''+dataurl.img);
					$(".name").html(dataurl.goodsName);
					
					$(".price big").html(dataurl.price);
					$(".price .integral").html(dataurl.integral+"积分");
					$(".goods_left span").html(dataurl.goods_left);
					$(".goods_detail").html(dataurl.goods_detail);
					for(var i=0;i<$(".goods_detail img").length;i++){
						$(".goods_detail img").eq(i).attr("src",H_SRC+$(".goods_detail img").eq(i).attr("src"));
					}
//					$(".name").html(dataurl.desc);
					goodname=dataurl.goodsName; 
					gooddesc=dataurl.desc;
					$(".taobao_url").attr("data-href",dataurl.taobao_url)
				}else{
					mui.toast(data.msg);
				}
			},
			error:function(){
				
			}
		}) 
		
		mui.ajax(H_SRC+'/amier/index/hidden',{
			data:{
				token:token
			},
			dataType:'json',
			type:'post',
			timeout:10000,             
			success:function(data){ 
				if(data.hidden==0){
					var html='<div class="mui-col-xs-12"><a href="javascript:void(0)" class="goods_exchange">立即兑换</a></div>'
				}else{
					var html='<div class="mui-col-xs-6"><a href="javascript:void(0)" class="goods_exchange">立即兑换</a></div><div class="mui-col-xs-6"><a data-href="" class="taobao_url">立即购买</a></div>'
				}
				$(".btnf").html(html);
				$(".goods_exchange").on("tap",function(){ 
			  		if(token==null){
						mui.openWindow({
							url:'login.html',
							id:'login.html',
							createNew:true,
							show: {
								autoShow: true,
								aniShow: 'slide-in-right',
								duration: 200
							}
						});
					}else{
						mui.ajax(H_SRC+'/amier/index/judge_points',{
							data:{
								token:token,
								gid:gid
							},
							dataType:'json',
							type:'post',
							timeout:10000,             
							success:function(data){ 
								var dataurl=data.data;
								if(data.code == 0){
									mui.alert("您的积分不够","友情提示");
								}else{
									mui.openWindow({
										url:'dhaddress.html',
										id:'dhaddress.html',
										createNew:true,
										extras:{
											gid:gid
										},
										show: {
											autoShow: true,
											aniShow: 'slide-in-right',
											duration: 200
										}
									});
								}
							},
							error:function(){
								
							}
						}) 
					}
			  	})
				
				$(".taobao_url").on("tap",function(){
					var hurl=$(this).attr("data-href");   
					plus.runtime.openURL(hurl);
				})
			},
			error:function(){
				
			}
		}) 
	})
	
	
	function shareWeixinMessage(type){
		var type=type;
		if(type==1){
			var secne="WXSceneSession"
		}else{
			var secne="WXSceneTimeline"
		}
		sharewx.send( 
			{ 
				title:goodname,
				content:gooddesc, 
				href:H_SRC+'/goods_detail/'+gid,
				thumbs: [goodimg], 
	        	pictures: [goodimg], 
				extra:{scene:secne}
			}, 
			function(){
				mask.close();
				$(".shareWx").addClass("mui-hidden");
				mui.toast( "分享成功！" );
			}, function(e){
				mask.close();
				$(".shareWx").addClass("mui-hidden");
				mui.toast( "取消分享");
			}
		);
	}
    </script>
</body>
</html>